package com.huangfu.learning.javabase.java.pattern.structure.adapter;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/8/7
 * Time: 20:13
 * Version: 1.0
 * Description: 其他实例
 **/
public class AdapterPattern2 {

    // 测试
    public static void main(String[] args) {
        /**************测试1  类适配****************/
        Ps2 p = new Adapter();
        p.isPs2();

        /**************测试2  对象适配****************/
        Ps2 p2 = new Adapter2(new Usber());
        p.isPs2();
    }
}

//ps2接口：Ps2
interface Ps2 {
    void isPs2();
}

//USB接口：Usb
interface Usb {
    void isUsb();
}

// USB接口实现类：Usber
class Usber implements Usb {

    @Override
    public void isUsb() {
        System.out.println("USB口");

    }
}

/**
 * 类适配
 */
//适配器：Adapter
class Adapter extends Usber implements Ps2 {

    @Override
    public void isPs2() {
        isUsb();
    }
}

/**
 * 对象适配器模式
 */

class Adapter2 implements Ps2 {

    private Usb usb;

    public Adapter2(Usb usb) {
        this.usb = usb;
    }

    @Override
    public void isPs2() {
        usb.isUsb();
    }

}
